package imp;

import java.util.*;
import java.text.DateFormat;

public class RelojRunnableDemo implements Runnable
{
    private Thread thrHora;
    private static javax.swing.JLabel lblHora;    
    
    public RelojRunnableDemo() {
        iniLabel();
        thrHora = new Thread(this,"hora");
        thrHora.start();
    }
    
    private void iniLabel() {
        lblHora = new javax.swing.JLabel();
        lblHora.setFont(new java.awt.Font("Dialog", 0, 24));
        lblHora.setForeground(new java.awt.Color(0, 102, 102));
        lblHora.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblHora.setBorder(new javax.swing.border.EtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        lblHora.setPreferredSize(new java.awt.Dimension(120, 40));
    }
    
    public void run() {
        while( thrHora == Thread.currentThread() ) {
            verHora();
            try {
                Thread.sleep(1000);
            } catch(InterruptedException e) {}
        }
    }
    
    private void verHora() {
        Calendar cal = Calendar.getInstance();
        Date date = cal.getTime();
        DateFormat dfmt = DateFormat.getTimeInstance();
        lblHora.setText(dfmt.format(date));
    }
    
    public static void main(String args[]) {
        new RelojRunnableDemo();
        javax.swing.JOptionPane.showMessageDialog(null,
                    lblHora,
                    "RunnableReloj",
                    javax.swing.JOptionPane.PLAIN_MESSAGE);
        System.exit(0);
    }           
}